package code._15network.udp.v4;

import untils.NetworkUtils;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ReciveTask implements Runnable{
    DatagramSocket datagramSocket;
    public ReciveTask(DatagramSocket datagramSocket) {
        this.datagramSocket = datagramSocket;
    }
    @Override
    public void run() {
        while (true){
            DatagramPacket recivePacket = NetworkUtils.getRecivePacket();
            try {
                datagramSocket.receive(recivePacket);
                String msg = NetworkUtils.parseMsg(recivePacket);
                /*if(recivePacket.getAddress().getHostAddress().equals("192.168.101.114")){
                    System.out.println("msg = " + msg);
                }*/
                System.out.println("msg = " + msg);

            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
